home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swaga_c.zip / CMDLINE.SWG / 0001_Get Command line INFO.pas next >
Pascal/Delphi Source File  |  1993-05-28  |  2KB  |  79 lines

  1. {
  2. > This leads me to a question that I've often wondered about, but never
  3. > Really bothered to ask anyone: why use a delimiter (commonly '/' or '-')
  4. > preceeding the parameter option?
  5.  
  6. How would you parse the following command tail:
  7.  
  8. COPY XYZZY.PAS V:\/S/P/O
  9.  
  10. if it was entered as
  11.  
  12. COPY XYZZY.PAS V:\SPO
  13.  
  14. The delimiter is there to - yes - delimit the parameter from the Text preceding
  15. it.
  16.  
  17. (and BTW: All the code examples shown here won't take care of this problem,
  18. since they don't allow imbedded parameters. Try this one instead:)
  19. }
  20.  
  21. Function CAPS(S : String) : String; Assembler;
  22. Asm
  23.   PUSH    DS
  24.   LDS     SI,S
  25.   LES     DI,@Result
  26.   CLD
  27.   LODSB
  28.   STOSB
  29.   xor     CH,CH
  30.   MOV     CL,AL
  31.   JCXZ    @OUT
  32. @LOOP:  LODSB
  33.   CMP     AL,'a'
  34.   JB      @NEXT
  35.   CMP     AL,'z'
  36.   JA      @NEXT
  37.   SUB     AL,20h
  38. @NEXT:  STOSB
  39.   LOOP    @LOOP
  40. @OUT:   POP   DS
  41. end;
  42.  
  43. Function Switch(C : Char) : Boolean;
  44. Var
  45.   CommandTail         : ^String;
  46.   P                   : Word;
  47.  
  48. begin
  49.   CommandTail := PTR(PrefixSeg, $0080);
  50.   P := POS('/' + UpCase(C), CAPS(CommandTail^));
  51.   if P = 0 then
  52.     Switch := False
  53.   ELSE
  54.   begin
  55.     Switch := True;
  56.     DELETE(CommandTail^, P, 2)
  57.   end
  58. end;
  59.  
  60. {
  61. The CAPS routine only converts the 'a' to 'z' range (I have one in my library
  62. that converts all international Characters, but this was a simple one I could
  63. Type in without looking in my library).
  64.  
  65. The Switch Function also has the added benefit that it strips off the switch
  66. from the command line after having tested For it. This way, you should Program
  67. your Programs in the following way:
  68.  
  69. [...]
  70. }
  71. begin
  72.   GetSwitchs;
  73.   CopyFile(ParamStr(1),ParamStr(2))
  74. end.
  75.  
  76. {
  77. and the switches can then be at ANY place on the command line, and the Program
  78. will still Function correctly.
  79. }